home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / KBSETUP.ARJ / KBSETUP.C next >
C/C++ Source or Header  |  1992-06-13  |  3KB  |  80 lines

  1. /*
  2.      *****************************************************************
  3.      *  program: KBSETUP.C         programmer: Andy Kellett          *
  4.      *  written: 05/16/91          using Turbo C v2.0                *
  5.      *  This program allows changing the keyboard key-repeat rate    *
  6.      *  (delay and speed) for AT and compatibles, also PS/2 models.  *
  7.      *  Will not work on PC or XT models.  PC World p.251-252 12/90  *
  8.      *  original Turbo C version by Michael O'Connor                 *
  9.      *  last updated: 06/13/91  Converted back to TC from PowerC     *
  10.      *****************************************************************
  11. */
  12.  
  13. #include <ctype.h>
  14. #include <dos.h>
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17.  
  18. #define ISIN(l,h,v)  ((l<=v)&&(v<=h))
  19.  
  20. int kbdelay = 0;     /*  Default typematic delay  */
  21. int kbrepeat = 0;    /*  Default repeat rate      */
  22.  
  23. void usage(void)
  24. {
  25.     puts("ERROR: Type KBSETUP M for menu\n");
  26.     exit(1);
  27. }
  28.  
  29. void menu(void)
  30. {
  31.     /*----- problems?  Prompt user with usage help -----*/
  32.     clrscr();
  33.     printf("\n\tKBSETUP MENU:     Michael O'Connor using TurboC v2.0\n");
  34.     printf("\t  keyboard DELAY time == delay in msecs\n");
  35.     printf("\t             A        ==       250\n");
  36.     printf("\t             B        ==       500\n");
  37.     printf("\t             C        ==       750\n");
  38.     printf("\t             D        ==      1000\n");
  39.     printf("\tkeyboard REPEAT rate  == characters per second\n");
  40.     printf("0 == 30.0\t   8 == 15.0\t   16 == 7.5\t   24 == 3.7\n");
  41.     printf("1 == 26.7\t   9 == 13.3\t   17 == 6.7\t   25 == 3.3\n");
  42.     printf("2 == 24.0\t  10 == 12.0\t   18 == 6.0\t   26 == 3.0\n");
  43.     printf("3 == 21.8\t  11 == 10.9\t   19 == 5.5\t   27 == 2.7\n");
  44.     printf("4 == 20.0\t  12 == 10.0\t   20 == 5.0\t   28 == 2.5\n");
  45.     printf("5 == 18.5\t  13 ==  9.2\t   21 == 4.6\t   29 == 2.3\n");
  46.     printf("6 == 17.1\t  14 ==  8.6\t   22 == 4.3\t   30 == 2.1\n");
  47.     printf("7 == 16.0\t  15 ==  8.0\t   23 == 4.0\t   31 == 2.0\n");
  48.     printf("\tSyntax: kbsetup <A...D> <0...31>\n");
  49.     printf("\tDefault settings: A 0 (short delay, fast repeat)\n");
  50.     exit(1);
  51. }
  52.  
  53. void main(int argc, char *argv[])
  54. {
  55.     int i;
  56.     union REGS reg;
  57.  
  58.     if (toupper(argv[1][0])== 'M') menu();
  59.     else for (i = 1; i < argc; i++)
  60.        if (isdigit(*argv[i])) {
  61.         kbrepeat = atoi(argv[i]);
  62.         if (!ISIN(0, 31, kbrepeat)) usage();
  63.     } else {
  64.         argv[i][0] = toupper(argv[i][0]);
  65.         if (!ISIN('A', 'D', argv[i][0])) usage();
  66.         kbdelay = argv[i][0] - 'A';
  67.     }
  68.  
  69.     /*-----  SET THE AX REGISTER TO 0305h, BH REGISTER TO DELAY VALUE -----
  70.       -----  BL TO TYPEMATIC RATE, THEN CALL INT 16h, FUNCTION 0305h  ----- */
  71.     reg.x.ax = 0x0305;
  72.     reg.h.bh = kbdelay;
  73.     reg.h.bl = kbrepeat;
  74.     int86(0x16, ®, ®);
  75.  
  76.     printf("\tSyntax: kbsetup <A...D> <0...31>\n");
  77.     printf("\tDefault settings: A 0 (short delay, fast repeat)\n");
  78. }
  79.  
  80.